<template>
 <div style="padding-top: 20px">
   <el-table :data="tableData" style="width: 100%">
     <el-table-column fixed prop="id" label="id" width="150" />
     <el-table-column prop="adminId" label="管理员Id" width="200" />
     <el-table-column prop="declareDate" label="发布时间" width="200" />
     <el-table-column prop="noticeBody" label="通知内容" width="500" />
     <el-table-column fixed="right" label="Operations" width="150">
       <template #default>
         <!--        <el-button link type="primary" size="small" @click="handleClick">查看-->
         <!--        </el-button>-->
       </template>
     </el-table-column>
   </el-table>
   <div class="demo-pagination-block">
     <div class="demonstration"></div>
     <h4>总页数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     </h4>
     <el-pagination
         v-model:current-page=current
         :page-size=size
         :small="small"
         :disabled="disabled"
         :background="background"
         layout="total, prev, pager, next"
         :total=total
         @size-change="getSizeChange"
         @current-change="getCurrentPage"
     />
   </div>
 </div>
</template>

<script>

import request from "@/utils/request";
import router from "@/router";

export default {
  name:"NoticeTable",
  components: {},

  created() {
    this.load()
  },

  methods: {
    load() {
      let user = sessionStorage.getItem("User")
      this.userId = JSON.parse(user).userId
      request.get("/user/noticeSelect/"+this.current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("用户id返回错误,返回推荐页面!")
          router.push("/CommentView")
        } else {
          if (res.data.records!=null){
            this.tableData=res.data.records
            this.total=res.data.total
            this.size=res.data.size
            this.pages=res.data.pages
          }
          else {
            this.tableData=res.data
          }
        }
      })
    },

    getCurrentPage(current){
      // alert(current)
      //获取当前页文章
      request.get("/user/noticeSelect/"+current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("用户id返回错误,返回最新文章页面!")
          router.push("/NowView")
        } else {
          this.articleList=res.data.records
          console.log(res.data.records)
          this.total=res.data.total
          this.size=res.data.size
          this.pages=res.data.pages
        }
      })
    },
  },

  data(){
    return{
      tableData:[
        {
          id:'',
          authorId:'',
          title:'',
          summary:'',
          coverImage:'',
          weight:'',
        }
      ],

      userId: '',
      total: 6,
      size: 12,
      current: 1,
      pages: 10,
    }
  }
}


</script>
